package com.aprivate.kn.ratingsystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aprivate.kn.ratingsystem.R;
import com.aprivate.kn.ratingsystem.bean.RatingQuestionBean;
import com.example.customcarcount.CounterView;

import java.util.List;

/**
 * Created by zhangshaokun on 2018/12/16.
 */

public class RatingAdapter extends android.widget.BaseAdapter {
    private Context mContext;
    private List<RatingQuestionBean> mData;

    public RatingAdapter(Context context, List<RatingQuestionBean> data) {
        this.mContext = context;
        this.mData = data;
    }

    @Override
    public int getCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public RatingQuestionBean getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
//        if (view == null) {
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.item_rating, null);
            view.setTag(viewHolder);
            viewHolder.itemTitle = view.findViewById(R.id.item_title);
            viewHolder.mRadio = view.findViewById(R.id.rlly_radio);
            viewHolder.mCheckbox = view.findViewById(R.id.rlly_checkBox);
            viewHolder.mEdit = view.findViewById(R.id.rlly_edit);
            viewHolder.mTitleRadio = view.findViewById(R.id.tv_title_radio);
            viewHolder.mTitleCheckBox = view.findViewById(R.id.tv_title_check);
            viewHolder.mTitleEdit = view.findViewById(R.id.tv_title_edit);
            viewHolder.mRadioGroup = view.findViewById(R.id.rd_group);
            viewHolder.mCheckboxLayout = view.findViewById(R.id.lly_checkbox);
            viewHolder.mEditView = view.findViewById(R.id.et_answer);
            viewHolder.mRadioZhiNan = view.findViewById(R.id.tv_radio_zhinan);
            viewHolder.mRadioZhengJu = view.findViewById(R.id.tv_radio_zhengju);
            viewHolder.mCheckBoxZhiNan = view.findViewById(R.id.tv_check_zhinan);
            viewHolder.mCheckBoxZhengJu = view.findViewById(R.id.tv_check_zhengju);
            viewHolder.mEditZhiNan = view.findViewById(R.id.tv_edit_zhinan);
            viewHolder.mEditZhengJu = view.findViewById(R.id.tv_edit_zhengju);
            viewHolder.mRadioNA = view.findViewById(R.id.checkbox_radio_na);
            viewHolder.mCheckNA = view.findViewById(R.id.checkbox_check_na);
            viewHolder.mEditNA = view.findViewById(R.id.checkbox_edit_na);
//        } else {
//            viewHolder = (ViewHolder) view.getTag();
//        }
        if (null != mOnViewHolder) {
            mOnViewHolder.setQustionDataToView(viewHolder, i, getItem(i));
        }
        return view;
    }


    private OnViewHolder mOnViewHolder;

    public interface OnViewHolder {
        void setQustionDataToView(ViewHolder viewHolder, int position, RatingQuestionBean bean);
    }

    public void setOnViewHolder(OnViewHolder onViewHolder) {
        this.mOnViewHolder = onViewHolder;
    }

    public static class ViewHolder {
        public TextView itemTitle;
        public RelativeLayout mRadio, mCheckbox, mEdit;
        public TextView mTitleRadio, mTitleCheckBox, mTitleEdit;
        public RadioGroup mRadioGroup;
        public LinearLayout mCheckboxLayout;
        public CounterView mEditView;
        public Button mRadioZhiNan, mRadioZhengJu, mCheckBoxZhiNan, mCheckBoxZhengJu, mEditZhiNan, mEditZhengJu;
        public CheckBox mRadioNA,mCheckNA,mEditNA;
    }
}
